{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import roslaunch\n",
    "import rospy\n",
    "import os\n",
    "\n",
    "def add_launch(object_list,pkg,file,args=[]):\n",
    "    \"\"\"\n",
    "    查找launch路径\n",
    "    :param object_list: 启动列表，将在函数内修改\n",
    "    :param pkg: 功能包名称\n",
    "    :param file: launch文件名\n",
    "    :param arg: launch的可选参数配置列表,[\"param1 := num1\", \"param2:=num2\"] \n",
    "    :return: 添加是否成功\n",
    "    \"\"\"\n",
    "    ros_path = os.environ['ROS_PACKAGE_PATH']\n",
    "    cli_args = []\n",
    "    for dir in ros_path.split(':'):\n",
    "        path = os.path.join(dir,pkg)\n",
    "        if os.path.exists(path):\n",
    "            path = os.path.join(os.path.join(path,'launch'),file)\n",
    "            if os.path.exists:\n",
    "                cli_args.append(path)\n",
    "                if len(args) == 0:\n",
    "                    object_list.append(path)\n",
    "                else:\n",
    "                    for arg in args:\n",
    "                        cli_args.append(arg)\n",
    "                    object_list.append((roslaunch.rlutil.resolve_launch_arguments(cli_args)[0],cli_args[1:]))\n",
    "                return True\n",
    "        else:\n",
    "            rospy.logerr('未找到launch文件,pkg:'+pkg+',file:'+file)\n",
    "            return False\n",
    "    \n",
    "def create_launchList(launch):\n",
    "    \"\"\"\n",
    "    launch = [{'pkg':'','file':'','args':[['arg1:=num1'],[...],...]},{...},{...},...]\n",
    "    \"\"\"\n",
    "    launchList = []\n",
    "    for Dict in launch:\n",
    "        add_launch(launchList,Dict['pkg'],Dict['file'],Dict['args'])\n",
    "    uuid = roslaunch.rlutil.get_or_generate_uuid(str(os.getppid()), False)\n",
    "    rosbridge_launch = roslaunch.parent.ROSLaunchParent(uuid,launchList)\n",
    "    return rosbridge_launch     "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
